package cn.wolfcode.wolf2w.redis.util;

import cn.wolfcode.wolf2w.util.Consts;
import lombok.Getter;

@Getter
public enum RedisKeys {
    //攻略统计vo的key
    STRATEGY_STATIS_VO("strategy_statis_vo",-1L),
    //攻略收藏id 的key
    STRATRGY_FAVOR("stratrgy_favor",-1L),
    //攻略置顶标记
    STRATRGY_THUMBUP("stratrgy_thumbup",-1L ),
    //标记vo对象
    STRATEGY_VO("strategy_vo",-1L),
    //短信验证码实例对象
    VERIFY_CODE("verify_code", Consts.VERIFY_CODE_VAI_TIME *60L),
    //登录的key实例对象
    USER_TOKEN("user_token", Consts.USER_INFO_TOKEN_VAI_TIME *60L);

    //key前缀
    private String prefix;
    //key有效时间
    private Long time;

    //构造器必须是私有的
    //JVM为了保证每一个枚举类的唯一实例，不允许外部new出来，进行私有化，防止用户意外new对象，破坏唯一性
    private RedisKeys(String prefix,Long time){
        this.prefix = prefix;
        this.time = time;
    }
    public String join(String... values){
        StringBuffer sb = new StringBuffer(80);
        sb.append(this.prefix);
        for (String value : values){
            sb.append(":").append(value);
        }
        return sb.toString();
    }

}
